<template>
	<view class=" item-main">
<!-- 		<view class="item-top"  v-if="isReward">
			<span class='left' @click="toDetail">{{item.title}}</span>、
			<div class="acea-row">
				
				<template v-if="item.isReward==2">
					<span class='right' @click="publish " style="margin-right: 3px;">发布悬赏</span>
				</template>
				<template v-else>
					<span class='right' @click="publish" style="margin-right: 3px;">修改悬赏</span>
					<template v-if="item.rewardStatus == 1">
						<span class='right' @click="setReward(0)" style="margin-right: 3px;">打开悬赏</span>
						<span class='right' v-if="item.trusteeship !='1'" @click="deleteReward" style="margin-right: 3px;">删除悬赏</span>
					</template>
					<template v-else>
						<span class='right' @click="setReward(1)" style="margin-right: 3px;">关闭悬赏</span>
					</template>
				</template>
				<span class='right rt' @click="tgMeth(item.rewardId)"
					v-if="item.isReward == '1' &&item.trusteeship !='1'">立即托管</span>
			</div>

		</view> -->
		<rewaredComp :item="item" :rewardType="item.status == 0 ? 5: 12" @tgMeth="tgMeth" @updateItem ="(k,v)=>$emit('updateItem', k, v)" />
		<view class="item-center" @click="toDetail">
			<view class="acea-row" style="flex-wrap: nowrap;">
				<img class='item-img'
					:src="item.products && item.products.length>0?(item.products[0].image?item.products[0].image.split(',')[0]:noImageShow) : noImageShow"
					alt="">
				<view class="content-main">
					<p>信息标题：{{item.title}}</p>
					<p>信息类目：{{item.categorySonName || ''}}</p>
					<!-- <p>商品数量：{{item.product?item.products.length : 0}}</p> -->
					<p>地址：{{item.address || ''}}</p>
				</view>
			</view>
			<!-- <span>审核中</span> -->
		</view>
		<view class="item-bottom" v-if="isContact">
			<p>已为您匹配到1200人·浏览 {{item.view || 0}} ·咨询0</p>
			<view class="bottom-btn">
				<span
					@click="item.sort != '1'?$emit('to-topping',item.id,'unused'):null">{{item.sort == '1'?'已置顶':'置顶'}}</span>
				<span>群发</span>
				<span @click="$emit('toVip',item)" :class="item.isVip== 1?'vip':''">
					{{item.isVip == '1'?'VIP信息':'VIP'}}</span>
				<span @click="$emit('visitor',item)">访客</span>
				<span @click="jumpPage">编辑</span>
				<span @click="$emit('setMeth',item)">设置</span>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		reardTrusteeship,
		closeReward,
		deleteReward
	} from '@/api/api.js'
	import {
		toPage
	} from '@/filters/commFilter.js'
	import rewaredComp from './publishReward/index.vue'
	export default {
		components:{
			rewaredComp
		},
		props: {
			item: {
				type: Object,
				default: () => ({})
			},
			categoryOn: {
				type: Number,
				default: 0
			},
			typeOn: {
				type: Number,
				default: 0
			},
			isContact: {
				type: Boolean,
				default: true
			},
			isReward: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				noImageShow: this.$noImageShow
			}
		},
		methods: {
			toDetail() {
				uni.navigateTo({
					url: '/pages/details/unused/unused?mind= 1&id=' + this.item.id
				})
			},
			publish() {
				let d = {...this.item};
				d.type = d.status == 1? 5:12;
				console.log("this.item.type", this.item.type)
				let item = JSON.stringify(d);
				uni.navigateTo({
					url: '/pages/releases/offeraRreward/offeraRreward?item=' + item
				})
			},
			jumpPage() {
				toPage('/pages/releases/unused/unused?typeOn=' + (this.typeOn) + '&categoryOn=' + (this.categoryOn) +
					'&id=' + this.item.id)
			},
			setReward(st){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否'+(st==1?'关闭':'打开')+'当前悬赏',
					success: function (res) {
						if (res.confirm) {
							closeReward({
								id: that.item.rewardId,
								status: st
							}).then(res=>{
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem",'rewardStatus',st)
								that.$util.Tips({
									title: (st==1?'关闭':'打开')+'悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
				
			},
			deleteReward(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '是否删除当前悬赏',
					success: function (res) {
						if (res.confirm) {
							console.log("that.item.rewardId",that.item.rewardId)
							deleteReward(that.item.rewardId).then(res=>{
								// that.item. 'rewardStatus' = st;
								that.$emit("updateItem",'isReward',2)
								that.$util.Tips({
									title: '删除悬赏成功'
								})
								// that.item.rewardStatus = st;
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			//托管方法
			tgMeth(id) {
				let that = this;
				console.log(id)
				uni.showModal({
					title: "提示",
					content: "是否立即托管",
					success(res) {
						if (res.confirm) {
							reardTrusteeship({
								id
							}).then(res => {
								if (res.code == 200) {
									that.$util.Tips({
										title: '托管成功'
									})
									setTimeout(() => {
										that.page = 1;
										that.initList();
									}, 1500)

								}
							}).catch(e => {
								that.$util.Tips({
									title: e
								}, {
									tab: 2,
									url: "/pages/users/user_money/index"
								})
							})
						}
					}

				})

			},
		}
	}
</script>

<style lang="scss">
	.item-main {
		padding-bottom: 36rpx;
		background-color: #ffffff;
		margin: 0rpx 28rpx;
		border-radius: 2rpx;
		padding: 0rpx 24rpx 0rpx 28rpx;

		.item-top {
			// margin: 0rpx 24rpx 0rpx 28rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 86rpx;

			.left {
				font-size: 30rpx;
				font-weight: 400;
				color: rgba(56, 56, 56, 1);
			}

			.right {
				border-radius: 10rpx;
				background-color: rgb(238, 33, 45);
				color: rgba(255, 255, 255, 1);
				font-size: 24rpx;
				width: 122rpx;
				height: 44rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.item-center {
			display: flex;
			justify-content: space-between;
			margin-top: 36rpx;
			padding-bottom: 40rpx;
			border-bottom: 2rpx solid rgba(238, 238, 238, 1);

			.acea-row {
				display: flex;
				align-items: center;

				.item-img {
					width: 170rpx;
					height: 144rpx;
					border-radius: 10rpx;
					margin-right: 18rpx;
				}

				.content-main {
					max-width: 435rpx;
					font-size: 24rpx;
					font-weight: 400;
					line-height: 20px;
					color: rgba(128, 128, 128, 1);

					p {
						margin: 0;
						padding: 0;
					}
				}
			}

			span {
				font-size: 22rpx;
				font-weight: 400;
				color: rgba(238, 33, 45, 1);
			}
		}

		.item-bottom {
			p {
				margin-top: 20rpx;
				font-size: 22rpx;
				font-weight: 400;
				line-height: 40rpx;
				color: rgba(166, 166, 166, 1);
			}

			.bottom-btn {
				padding-bottom: 36rpx;
				margin-top: 18rpx;
				display: flex;
				justify-content: space-between;

				span {
					font-size: 24rpx;
					color: rgba(128, 128, 128, 1);
					width: 90rpx;
					line-height: 44rpx;
					border-radius: 4rpx;
					border: 2rpx solid rgba(229, 229, 229, 1);
					display: flex;
					justify-content: center;
				}
			}
		}
	}

	.v {
		// display: flex;
		margin-left: 10rpx;
		padding: 1rpx 10rpx;
	}

	.vip {
		border: 1px solid red !important;
		color: red !important;
	}
</style>